home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-02-05 | 12.4 KB | 400 lines | [TEXT/MPS ] |
- ; ---------------------------------------------------------------------
- ;
- ; Assembly source for XWindShell XCMD
- ;
- ; Copyright © 1989-92 Apple Computer, Inc.
- ;
- ;
- ; This file includes the source code for the XWindShell XCMD. While
- ; this XCMD will compile and execute in its current form. The XWindow
- ; has no functionality beyond demonstrating the basics of HyperCard's
- ; XWindow capabilities. This file is meant to be the basis where an
- ; XCMD author can "fill in the blanks" to create their XCMD. See the
- ; other sample XCMDs such as Picture, MemState, and ListWindow for
- ; practical examples of code dealing with responding to XWindow events
- ; and strategies for storing information for the XWindows while they
- ; are open.
- ;
- ; The files included with the XWindShell XCMD are meant to be
- ; used as a starting point for assembly XCMDs wishing to create and
- ; manage XWindows.
- ;
- ; NOTE: This XCMD is expressly designed to avoid a lot of stack
- ; frame operations. This is suitable for most XCMDs. Large,
- ; complex XCMDs may wish to divide the source into smaller,
- ; more manageable procedures with their own local variables.
- ;
- ; Files:
- ; ------
- ; *XWindShell.a
- ; XWindShell.r
- ; MakeFile
- ;
- ;
- ; Author: Darin Acquistapace
- ; Created: 02/04/92
- ; Modified: See Mod History Below
- ;
- ; Modification History:
- ; ---------------------
- ; 02/04/92 - New today.
- ;
- ; ---------------------------------------------------------------------
-
- INCLUDE 'E16.Event'
- INCLUDE 'E16.HyperXCMD'
- INCLUDE 'New.Stack.Macros'
- INCLUDE 'M16.Memory'
- INCLUDE 'M16.Window'
- INCLUDE 'M16.QuickDraw'
- INCLUDE 'M16.HyperXCMD'
-
- LONGA ON
- LONGI ON
-
- XWindShell PROC EXPORT
-
- InitFrame
-
- ExclamationPt EQU $0021 ; ASCII values of "!" & "?"
- QuestionMark EQU $003f
-
- xWindow Local Ptr
- tempHandle Local Handle
- tempPtr Local Ptr
-
- paramPtr Param Ptr
-
- EntryCode
-
- lda [<paramPtr] ; Get the paramCount
- bpl NotEventCall ; If not negative, continue
- jsr HandleEvents ; Otherwise handle the event
- brl Exit ; and leave
-
- NotEventCall cmp #01 ; If we have one parameter,
- bne CheckParamCnt ; check it for "!" or "?"
- ldy #oxbParams+2
- lda [<paramPtr],y ; Get a pointer to the first
- sta <tempHandle+2 ; zero-terminated param
- dey
- dey
- lda [<paramPtr],y
- sta <tempHandle
- lda [<tempHandle]
- sta <tempPtr
- lda [<tempHandle],y
- sta <tempPtr+2
-
- lda [<tempPtr] ; Get the first param
- cmp #ExclamationPt ; Is it a "!"?
- bne CheckQuestion ; No, check for "?"
- pea CopyrightStr>>16
- pea CopyrightStr
- bra DoSendMessage
-
- CheckQuestion cmp #QuestionMark ; Is it "?"
- bne CheckParamCnt ; No, continue
- pea HelpStr>>16
- pea HelpStr
-
- DoSendMessage _SendHCMessage ; Display the dialog and leave
- bra Exit
-
- CheckParamCnt lda [<paramPtr] ; Get the paramCount
- beq ParamCountOK ; Zero is OK, o.w. show error
- bra HTError
-
- ParamCountOK jsr CorrectVersion ; Make sure we're running HCIIGS
- bne VersionOK ; version 1.1 or later
- ldx #WrongVersionStr>>16
- ldy #WrongVersionStr
- bra ReturnResult
-
- VersionOK pha
- pha
- pea windRect>>16 ; Create the new XWindow init-
- pea windRect ; ially invisible
- pea WindTitle>>16
- pea WindTitle
- pea 0 ; Visible (false)
- pea xWindoidStyle
- _NewXWindow
- pla
- sta <xWindow
- pla
- sta <xWindow+2
- ora <xWindow ; Make sure the NewXWindow call
- bne GoodXWindow ; succeeded
-
- ldx #CreateErrStr>>16 ; Return an error in the result
- ldy #CreateErrStr
- bra ReturnResult
-
- GoodXWindow pei <xWindow+2 ; Set the current port to the
- pei <xWindow ; new xWindow
- _SetPort
-
- jsr SetUpContents ; Handle any initialization
-
- pei <xWindow+2 ; Show the xWindow
- pei <xWindow
- _ShowWindow
- Exit
- ExitCode
-
- ; --------------------------------------------------------------------------
- HTError
- ; Generates a HyperTalk error dialog box complete with Script and Cancel
- ; buttons.
- ldy #oxbReturnStat ; Set returnStat to 1
- lda #01
- sta [<paramPtr],y
-
- ldx #ScriptErrStr>>16 ; Error msg returned in the
- ldy #ScriptErrStr ; result
- bra ReturnResult
-
- ; --------------------------------------------------------------------------
- ReturnResult
- ; Upon entry, x contains the high word of a ptr to a pascal string. Y
- ; contains the low word. This string is converted to a zero-terminated
- ; string. The handle containing this string is returned in the result.
- pha
- pha
- phx
- phy
- _PasToZero
- ldy #oxbReturnValue ; Set returnValue field of
- pla ; the paramBlock to the
- sta [<paramPtr],y ; zero-terminated string
- iny
- iny
- pla
- sta [<paramPtr],y
- bra Exit
-
- ; --------------------------------------------------------------------------
- SetUpContents
- ; Our window has been created via a call to the NewXWindow callback and is
- ; invisible. Now handle any initialization necessary for the XWindow such as
- ; calling NewControl, etc.
-
- rts
-
- ; --------------------------------------------------------------------------
- HandleEvents
- ; Handle events specific to our XWindow. HyperCard will only send events
- ; to the XCMD pertaining to windows it has opened. The XCMD, however,
- ; should not assume that it owns only one window. Subsequent calls to
- ; the XCMD to create the XWindow will result in one XCMD code segment
- ; owning multiple XWindows. This routine is similar to the main event loop
- ; of an application, all events dealing with the XWindows the XCMD has
- ; created will be sent here and dispatched to the appropriate routine to
- ; respond to them.
- ldy #oxbParams+2 ; Get the ptr to the
- lda [<paramPtr],y ; XWEventInfo record
- sta <tempPtr+2
- dey
- dey
- lda [<paramPtr],y
- sta <tempPtr
-
- lda [<tempPtr],y ; Get the target xWindow
- sta <xWindow+2
- dey
- dey
- lda [<tempPtr],y
- sta <xWindow
-
- ldy #04 ; Get event.what
- lda [<tempPtr],y
-
- bne @1 ; Check against each event
- bra ProcessIdle ; code. (nullEvt)
-
- @1 cmp #xOpenEvt ; (xOpenEvt)
- bne @2
- bra HandleOpenEvent
-
- @2 cmp #updateEvt ; (updateEvt)
- bne @3
- bra UpdateXWindow
-
- @3 cmp #mouseDownEvt ; (mouseDownEvt)
- bne @4
- bra HandleWindClick
-
- @4 cmp #xHidePalettesEvt ; (xHidePalettesEvt)
- beq @4a
- cmp #xShowPalettesEvt ; (xShowPalettesEvt)
- bne @5
- @4a bra HandleHideShow
-
- @5 cmp #xCloseEvt ; (xCloseEvt)
- bne @6
- bra CleanUpMemory
-
- @6 cmp #xCursorWithin ; (xCursorWithin)
- bne EventNotHandled
- bra HandleCursor
-
- EventNotHandled rts
-
- ; --------------------------------------------------------------------------
- ProcessIdle
- ; Take any actions that need to be performed periodically. This procedure
- ; will only be called if the SetXWIdleTime callback has been called with
- ; an interval value other than zero (the default.)
-
- rts
-
- ; --------------------------------------------------------------------------
- HandleOpenEvent
- ; Allow reentrancy, if this is not set, the XWindow may lose events that
- ; occur because of events instigated by the XCMD. For instance, if the
- ; mouseDown handler performs some action which causes HyperCard to close
- ; the XWindow, the xCloseEvt will not be received because the XCMD has the
- ; code in the mouseDown handler pending and will be returned to when Hyper-
- ; Card finishes executing whatever task the mouseDown handler began. This
- ; can be set to true for both types of events in most XCMDs and set to false
- ; temporarily if the need arises to temporarily halt recursive calls to the
- ; XCMD.
- ;
- ; If an XCMD wishes to receive null events, it should call SetXWIdleTime
- ; at this point with an interval other than zero.
-
- pei <xWindow+2
- pei <xWindow
- lda #01
- pha
- pha
- _XWAllowReEntrancy
-
- rts
-
- ; --------------------------------------------------------------------------
- UpdateXWindow
- ; Handles updating the contents of the XWindow. This may include drawing
- ; a background picture, calling DrawControls, etc. HyperCard takes care of
- ; calling BeginUpdate and EndUpdate for you. This routine should only update
- ; the window. Be careful not to do anything that might cause another update
- ; event to occur which would result in recursion.
-
- rts
-
- ; --------------------------------------------------------------------------
- HandleWindClick
- ; A mouseDown event has occurred in our window. This procedure handles
- ; tracking the click and taking whatever actions are necessary as a result
- ; of the click. Tracking controls in XWindows is no different than doing
- ; the same in any standard window. FindControl and TrackControl would be
- ; commonly used to track the click. See the Picture and ListWindow sample
- ; XCMDs for examples of using the control manager to handle these actions.
-
- rts
-
- ; --------------------------------------------------------------------------
- HandleHideShow
- ; An XCMD has called either the HideHCPalettes or ShowHCPalettes callbacks
- ; and our visible status has changed. An XCMD may wish to deallocate memory
- ; used for updating the XWindow if it knows it will be hidden for a period of
- ; time. An example usage would be if a significant amount of memory was
- ; required to maintain the contents of an XWindow. A script could call an
- ; XCMD to send the HidePalettes event when the user entered the paint tools
- ; so that the XCMD could free what memory it could to provide more memory
- ; for the paint buffers.
-
- rts
-
- ; --------------------------------------------------------------------------
- CleanUpMemory
- ; Free all memory associated with the XWindow. This could be a handle
- ; referenced by the GetXWindowValue callback.
-
- rts
-
- ; --------------------------------------------------------------------------
- HandleCursor
- ; The mouse cursor is within the XWindow, perform any actions necessary,
- ; such as changing the cursor shape.
- ldy #oxbPassFlag ; Let HC handle changing the
- lda #01 ; cursor
- sta [<paramPtr],y
- rts
-
- ; --------------------------------------------------------------------------
- MyDisposeHandle
- ; Checks a handle for NIL before disposing of it. A good practice. Upon
- ; entry, x contains high word of handle to be disposed and y contains the
- ; low word.
-
- stx <tempHandle ; Check handle for nil
- tya
- ora <tempHandle
- beq @1
-
- phx ; Not NIL, so dispose it
- phy
- _DisposeHandle
-
- @1 rts
-
- ; --------------------------------------------------------------------------
- CorrectVersion
- ; This returns 1 in the x reg. if the version of HyperCard is >= minVersion.
- ; Returns 0 in x o.w. Very important for XCMDs that use callbacks specific
- ; to 1.1 or later versions of HyperCard IIGS. HyperCard IIGS 1.0 will execute
- ; a BRK and take a one-way trip to the monitor or debugger if an XCMD attempts
- ; an invalid callback number. HyperCard IIGS 1.1 calls the SysFail manager
- ; with the message, "Invalid callback attempted by XCMD" if a callback numbered
- ; greater than $38 is attempted, BTW.
-
- pha ; Get the version in the form
- pha ; "1.x"
- pea versionStr>>16
- pea versionStr
- _EvalExpr
- pla
- sta <tempHandle
- pla
- sta <tempHandle+2
-
- ldy #02 ; Make a pointer to the zero-
- lda [<tempHandle] ; terminated string handle
- sta <tempPtr
- lda [<tempHandle],y
- sta <tempPtr+2
-
- lda [<tempPtr],y ; Look at the third character
- and #$00ff ; and compare it against the
- ldx #$00 ; ascii char "1"
- cmp #'1'
- blt @1
- inx
- @1 phx ; Save off our result
- ldx <tempHandle+2 ; We're responsible for getting
- ldy <tempHandle ; rid of the result of EvalExpr
- jsr MyDisposeHandle
- plx ; Restore our result
- rts
-
- ; --------------------------------------------------------------------------
- ; Constants used in the XCMD.
-
- windRect dc.w 50, 100, 110, 350
-
- STRING PASCAL
-
- versionStr dc.b 'the version';
- WindTitle dc.b 'SampleXWindow';
- ScriptErrStr dc.b 'Can''t understand arguments of XCMD XWindShell.'
- CopyrightStr dc.b 'answer "XWindShell XCMD v1.0" & return & "by Darin Acquistapace, 1/29/92" & return & "© 1992 Apple Computer, Inc."'
- HelpStr dc.b 'answer "FORM: XWindShell"'
- WrongVersionStr dc.b 'XWindShell XCMD requires HyperCard IIGS 1.1'
- CreateErrStr dc.b 'Unable to create window'
-
- ENDPROC
-
- END
-